package com.apptest.android.ui.architecture;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import com.apptest.android.core.bean.ArchitectureBean;
import com.apptest.android.util.CommonUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.apptest.android.R;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

public class ArchitectureAdapter extends BaseQuickAdapter<ArchitectureBean, BaseViewHolder> {

    public ArchitectureAdapter(int layoutResId, @Nullable List<ArchitectureBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ArchitectureBean item) {
        helper.setText(R.id.item_architecture_block_title,item.getName());
        TagFlowLayout flowLayout = helper.getView(R.id.item_architecture_block_layout);
        flowLayout.setMaxSelectCount(0);
        List<ArchitectureBean> children = item.getChildren();
        flowLayout.setAdapter(new TagAdapter<ArchitectureBean>(children) {
            @Override
            public View getView(FlowLayout parent, int position, ArchitectureBean architectureBean) {
                TextView viewTag = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_navigation_tag,
                        flowLayout, false);
                if(architectureBean == null)
                    return null;
                viewTag.setText(children.get(position).getName());
                viewTag.setTextColor(CommonUtils.getRandomColor());
                return viewTag;
            }
        });
    }
}
